<?php

/**
 * AdController - The default controller class
 *
 * @author
 * @version
 */

require_once 'Zend/Controller/Action.php';

class AdController extends Zend_Controller_Action
{



    public function init()
    {



    }

    public function preDispatch()
    {

        $this->view->addHelperPath(MY_ROOT.'/vhelpers');

        Zend_Controller_Action_HelperBroker::addPath(MY_ROOT.'/chelpers');

        $this->getHelper('Nav')->getHeaderNav();

        $this->getHelper('User')->getinfo($this->_request->getModuleName(),$this->_request->getControllerName());

    }


    public function indexAction()
    {

        $cateString=file_get_contents(MY_ROOT.'/html/upload/category/category.txt');

        $cateArray=array();

        if($cateString!='')
        {

            $cateArray=json_decode($cateString,true);

        }


        $item=new CItem();

       
        ////2010新风格标志.
        $newindexflag=0;
        $this->view->assign('newindexflag',$newindexflag);

        $footer="NO";
		 $this->view->assign('footer',$footer);
		 
		 $topmenu="NO";
		 $this->view->assign('topmenu',$topmenu);

        
         //����ҳ�м�������Ĳ�Ʒ������
        //nfl
        $productFl=new CFenlei('product');
        $flArray=$this->getHelper('Fenlei')->getFenleiChild($productFl->getFenleiTree(),1);
        $nflitemArray=array();
        if(count($flArray)>0)
        {
            $where=R_PRE."items.flid in (".join(',',$flArray).')';
            $nflitemArray=$item->getAllItems(0,3,'product',0,0,"has_banned",$where);
        }else
        {
            $nflitemArray=$item->getAllItems(0,3,'product',0,1);
        }
        $this->view->assign('nflitemArray',$nflitemArray);
        //soccer
        $flArray=$this->getHelper('Fenlei')->getFenleiChild($productFl->getFenleiTree(),91);
        $socceritemArray=array();
        if(count($flArray)>0)
        {
            $where=R_PRE."items.flid in (".join(',',$flArray).')';
            $socceritemArray=$item->getAllItems(0,3,'product',0,0,"has_banned",$where);
        }else
        {
            $socceritemArray=$item->getAllItems(0,3,'product',0,91);
        }
        $this->view->assign('socceritemArray',$socceritemArray);
        //nba
        $flArray=$this->getHelper('Fenlei')->getFenleiChild($productFl->getFenleiTree(),58);
        $nbaitemArray=array();
        if(count($flArray)>0)
        {
            $where=R_PRE."items.flid in (".join(',',$flArray).')';
            $nbaitemArray=$item->getAllItems(0,3,'product',0,0,"has_banned",$where);
        }else
        {
            $nbaitemArray=$item->getAllItems(0,3,'product',0,58);
        }
        $this->view->assign('nbaitemArray',$nbaitemArray);
        //nhl
        $flArray=$this->getHelper('Fenlei')->getFenleiChild($productFl->getFenleiTree(),109);
        $nhlitemArray=array();
        if(count($flArray)>0)
        {
            $where=R_PRE."items.flid in (".join(',',$flArray).')';
            $nhlitemArray=$item->getAllItems(0,3,'product',0,0,"has_banned",$where);
        }else
        {
            $nhlitemArray=$item->getAllItems(0,3,'product',0,1);
        }
        $this->view->assign('nhlitemArray',$nhlitemArray);




        //Chinese
        $flArray=$this->getHelper('Fenlei')->getFenleiChild($productFl->getFenleiTree(),170);
        $ChineseitemArray=array();
        if(count($flArray)>0)
        {
            $where=R_PRE."items.flid in (".join(',',$flArray).')';
            $ChineseitemArray=$item->getAllItems(0,3,'product',0,0,"has_banned",$where);
        }else
        {
            $ChineseitemArray=$item->getAllItems(0,3,'product',0,170);
        }
        $this->view->assign('ChineseitemArray',$ChineseitemArray);


        $itemArray=$item->getAllItems(0,$cateArray['product_cate'],'product',0,0);

        $this->view->assign('itemArray',$itemArray);


        $isHotItemArray=$item->getAllItems(0,$cateArray['hot_cate'],'product',0,0,"has_banned","type='1'",'view_num DESC');

        $this->view->assign('isHotItemArray',$isHotItemArray);


        $isNewItemArray=$item->getAllItems(0,$cateArray['new_cate'],'product',0,0,"has_banned","type='2'",'view_num DESC');

        $this->view->assign('isNewItemArray',$isNewItemArray);


        $isBestItemArray=$item->getAllItems(0,$cateArray['top_cate'],'product',0,0,"has_banned","type='3'",'view_num DESC');

        $this->view->assign('isBestItemArray',$isBestItemArray);


        $isGunItemArray=$item->getAllItems(0,8,'product',0,0,"has_banned","type='4'",'view_num DESC');

        $this->view->assign('isGunItemArray',$isGunItemArray);


        $this->getHelper('Fenlei')->getCategories();


        $imgString=file_get_contents(MY_ROOT.'/html/upload/turn_round/imgs.txt');

        $imgArray=array();

        $imgArray=json_decode($imgString,true);

        $newImgArray=$imgArray['imgUrl'];

        $newHrefArray=$imgArray['imgHref'];

        for($i=0;$i<count($imgArray['ordering']);$i++)
        {

            $imgArray['imgUrl'][$imgArray['ordering'][$i]]=$newImgArray[$i];

        }

        for($i=0;$i<count($imgArray['imgUrl']);$i++)
        {

            $imgArray['imgHref'][$imgArray['ordering'][$i]]=$newHrefArray[$i];

        }

        $this->view->assign('imgArray',$imgArray);

        $order=new COrder();

        $orderArray=$order->getAllOrders(0,8,0);

        $this->view->assign('orderArray',$orderArray);


        $bulletinArray=$item->getAllItems(0,10,'bulletin');

        $this->view->assign('bulletinArray',$bulletinArray);

        $this->view->assign ( "website_description", "Jersey,clothes" );

    //$this->view->assign ( "website_title", "Jersey shopping mall" );

    }



    public function getlocationajaxAction()
    {

        $this->_helper->viewRenderer->setNoRender();

        $this->getHelper ('layout')->disableLayout ();

        $pid=$this->_request->getParam('pid',0);

        $location=new CFenlei('location');

        $fenleiArray=$location->getFenleiByPid($pid);

        echo json_encode($fenleiArray);

    }

    public function userpanelAction()
    {

        $this->getHelper('User')->getinfo($this->_request->getModuleName(),$this->_request->getControllerName());

        $this->getHelper ('layout')->disableLayout ();

    }


    public function postAction()
    {

    //$this->_helper->viewRenderer->setNoRender();

    //$this->getHelper ('layout')->disableLayout ();

    }



}
